<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" layout:decorate="main"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
    <title>角色</title>
    <link th:href="@{/localcss/crmlist.css}" href="../static/localcss/crmadd.css" rel="stylesheet">
</head>
<body>
<div layout:fragment="content">
    <div class="">
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>修改角色信息 <i class="fa fa-user"></i></h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <div class="clearfix"></div>
                        <form class="form-horizontal form-label-left" th:action="@{/role/auth}" action="/role/auth"
                              method="post">
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="roleName"> 角色名 <span
                                        class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input th:value="${role.roleId}" name="roleId" type="hidden">
                                    <input th:value="${role.roleName}" id="roleName"
                                           class="form-control col-md-7 col-xs-12"
                                           data-validate-length-range="10" data-validate-words="1" name="roleName"
                                           required="required"
                                           placeholder="请输入角色名" type="text">
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="roleFlag"> 角色状态 <span
                                        class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <div class="col-md-6 col-sm-6 col-xs-12">
                                        <span>
                                            <input th:checked="${role.roleFlag} eq 1" type="checkbox" id="roleFlag"
                                                   name="roleFlag">
                                        </span>
                                        <span>(角色是否可用)</span>
                                    </div>
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="roleFlag"> 指派权限 <span
                                        class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <span><input type="checkbox" th:checked="${rightList.size() eq rights.size()}" name="authAll" onclick="selectAll()">&nbsp;全选</span>
                                    <div class="col-md-12 col-sm-12 col-xs-12"
                                         th:if="${right.rightType=='Folder'}"
                                         th:each="right:${rights}">

                                        <span>
                                            <input type="checkbox"
                                                   th:checked="${#lists.contains(rightList,right.rightCode)}"
                                                   th:value="${right.rightCode}" name="auth">
                                        </span>
                                        <span th:text="${right.rightText}">一级菜单</span>
                                        <!--二级菜单-->
                                        <div th:if="${right2.rightType=='Document' && right2.rightParentCode==right.rightCode}"
                                             th:each="right2:${rights}"
                                             class="col-md-12 col-sm-12 col-xs-12 col-md-offset-1">
                                        <span>
                                            <input type="checkbox"
                                                   th:checked="${#lists.contains(rightList,right2.rightCode)}"
                                                   name="auth" th:value="${right2.rightCode}">
                                        </span>
                                            <span th:text="${right2.rightText}">二级菜单</span>
                                            <!--三级菜单-->
                                            <div th:if="${right3.rightType=='Url' && right3.rightParentCode==right2.rightCode}"
                                                 th:each="right3:${rights}"
                                                 class="col-md-12 col-sm-12 col-xs-12 col-md-offset-1">
                                        <span>
                                            <input type="checkbox"
                                                   th:checked="${#lists.contains(rightList,right3.rightCode)}"
                                                   name="auth" th:value="${right3.rightCode}">
                                        </span>
                                                <span th:text="${right3.rightText}">三级菜单</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-3">
                                    <button id="send" type="submit" class="btn btn-success">保存</button>
                                    <button type="button" class="btn btn-primary" id="back">返回</button>
                                    <br/><br/>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script layout:fragment="js">
    $(document).ready(function () {
        $("#back").on("click", function () {
            window.location.href = '/crm/role/listPage';
        });
    });

    function selectAll() {
        var obj = document.getElementsByName("auth");
        var selected = document.getElementsByName("authAll");
        for (k in obj) {
            obj[k].checked = selected[0].checked;
        }
    }
</script>
</html>